<template>
	<view style="padding-top: 20upx;">
		<template v-if="userTalkList.length>0">
		<view @click="toTopic(index)" class="userTalkList" v-for="(item,index) in userTalkList" :key='index'>
			<view>{{item.fromUserName}}<text class="comment">{{item.commentContent?'回复了你':'评论了你'}}</text></view>
			<view>{{item.time}}</view>
			<view>{{item.content}}</view>
			<view class="myTalk"><text v-if="item.commentContent">@{{item.commentUserName}}</text><text>{{item.commentContent}}</text></view>
			<view>{{item.essayTitle}}</view>
		</view>
		</template>
        <template v-else>
			<no-thing></no-thing>
		</template>		
		<loadMore v-if="userTalkList.length>0" :loadtext="loadtext"></loadMore>
	</view>
</template>

<script>
	import noThing from"../../components/common/no-thing.vue"
	import loadMore from "../../components/common/load-more.vue"
	export default {
		components: {
			noThing,
			loadMore
		},
		data() {
			return {
				userTalkList:[],
				loadtext:"上拉加载更多",
				pagenum:1,
			};
		},
		onReady() {
			this.getAbout()
		},
		//监听触底事件
		onReachBottom(){
			this.loadmore()
		},
		methods:{
			//获取与我相关的消息
			getAbout(){
				uni.request({
					url:this.confige.webUrl+"/essay/listComment",
					header:{
						'X-Token':this.User.token
					},
					data:{
						limits:15,
						pages:1
					},
					success: (res) => {
						// console.log(res);
						this.userTalkList = res.data.result[0].list;
						if(this.userTalkList.length>14){
							this.loadtext ="上拉加载更多";
						}
						else{
							this.loadtext ="没有更多了";
						}
					}	
				})
			},
			loadmore(){
			   if(this.loadtext!="上拉加载更多"){ return;}
			   this.loadtext="加载中...";	
			   this.pagenum++;
			   setTimeout(() => {
				uni.request({
					url:this.confige.webUrl+"/essay/listComment",
					data:{
						limits:15,
						pages:this.pagenum
					},
					header:{
						'X-Token':this.User.token
					},
					success: (res) => {
						console.log(res)
						
						 if(res.data.code==200){
							 let list = res.data.result[0].list;
							 this.userTalkList.push(...list) ;
							this.loadtext="上拉加载更多"
						 }
						 else{
						 	this.loadtext="没有更多啦"
						     }
					 }	
					}	  
				)}, 1000);
			},
			toTopic(index){
				var id = this.userTalkList[index].essayId
				uni.navigateTo({
					url:"../indexTopic/topic?id="+id
				})
			}
		}
	}
</script>

<style lang="less" scoped>
 @import '../../common/global.less';
 page{ background-color: #FFFFFF;}
 .comment{
	 padding-left: 10rpx;
	 color: #949494;
	 font-weight:200;
 }
 .myTalk{ font-size: 28upx; overflow: hidden;white-space:nowrap;text-overflow: ellipsis;
	 >text:nth-of-type(1){color:#0081FF;}
	 >text:nth-of-type(2){padding-left: 20upx;}}
 .userTalkList{
	 width: 96%;
	 margin: auto;
	 padding-bottom: 10rpx;
	 >view{padding-top: 10upx;}
	 >view:nth-of-type(1){
		 font-size: 28upx;
		 font-weight: bold;
	 }
	 >view:nth-of-type(2){
	 		 font-size: 20upx;
			 color: @fontcolor;
	 }
	 >view:nth-of-type(3){
	 		 font-size: 30upx;
	 }
	 >view:nth-of-type(5){
		     padding: 20upx;
			 margin-top: 15upx;
	 		 font-size: 30upx;
			 border-radius: 20upx;
			  overflow: hidden;white-space:nowrap;text-overflow: ellipsis;
			 background-color: @backcolor;
	 }
	 }
</style>
